<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增首页活动信息')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-JiajiaHomeActivity-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">图片地址：</label>
            <div class="col-sm-8">
                <input id="file" accept="image/jpg,image/jpeg,image/png" name="file"  class="form-control" required type="file">
                <img style="width: 80px ;height: auto;" src="" id="imgPhoto"  />
                <input style="display: none" id="url" name="url" class="form-control"   type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型：</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b">
                    <option value="">请选择类型</option>
                    <option value="0">招聘</option>
                    <option value="1">活动</option>
                </select>
<!--                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>-->
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "jiajia/JiajiaHomeActivity"
    $("#form-JiajiaHomeActivity-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var formData = new FormData();
            formData.append('file',$(file)[0].files[0]);
            $.modal.loading("图片上传中，请稍后...")
            $.ajax({
                url: "/common/admin/upload/up/single",
                data: formData,
                type: "post",
                dataType: "json",
                processData: false,
                contentType: false,
                success: function(result) {
                    $("#url").val(result.url);
                    $.operate.save(prefix + "/add", $('#form-JiajiaHomeActivity-add').serialize());
                }
            })
        }
    }

    $("#file").bind('change', function () {
        $("#imgPhoto").show();
        $("#imgPhoto").attr("src",URL.createObjectURL($(this)[0].files[0]));

    });

    $("input[name='addtime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(".file-upload").fileinput({
        uploadUrl: ctx + '/common/admin/upload/up/single',
        maxFileCount: 1,
        autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
</script>
</body>
</html>
